/**
 * Copyright (c) 2021 Corona.
 * cBST is licensed under Mulan PSL v2.
 * You can use this software according to the terms and conditions of the Mulan PSL v2. 
 * You may obtain a copy of Mulan PSL v2 at:
 *          http://license.coscl.org.cn/MulanPSL2 
 * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.  
 * See the Mulan PSL v2 for more details.  
 */
#ifndef __CBST_H
#define __CBST_H

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#ifdef __cplusplus
extern "C" {
#endif

#define cBST_TRUE ((cBST_BOOL)1)
#define cBST_FALSE ((cBST_BOOL)0)

#define cBST_TYPE_INTEGER (1<<1)
#define cBST_TYPE_DOUBLE (1<<2)
#define cBST_TYPE_STRING (1<<3)

#define cBST_LEFT (2<<1)
#define cBST_RIGHT (2<<2)

typedef int cBST_BOOL;
typedef int cBST_INTEGER;

/**
 * cBST对象
 */
typedef struct cBST {
    int type;
    int valueInt;
    double valueDouble;
    char* valueString;
    cBST_BOOL isEmpty;

    struct cBST* father;
    struct cBST* leftChild;
    struct cBST* rightChild;

} cBST;

/**
 * Some Tools.
 */
cBST_BOOL cBST_HasLeftChild( cBST* );
cBST_BOOL cBST_HasRightChild( cBST* );
cBST_INTEGER cBST_Size( cBST* );
cBST_INTEGER cBST_Height( cBST* );

void cBST_Print( FILE*, const unsigned int, cBST* );
void cBST_PrintPretty( FILE*, cBST* );

/**
 * Create a New cBST.
 */
cBST* cBST_NewEmptyBST( void );
cBST* cBST_NewIntBST( const int );
cBST* cBST_NewDoubleBST( const double );
cBST* cBST_NewStringBST( const char* );

/**
 * Add Int/Double/String from a cBST;
 */
cBST_BOOL cBST_AddInt( cBST**, const int );
cBST_BOOL cBST_AddDouble( cBST**, const double );
cBST_BOOL cBST_AddString( cBST**, const char* );


/**
 * Search from a cBST.
 */
cBST_BOOL cBST_SearchInt( cBST*, const int );
cBST_BOOL cBST_SearchDouble( cBST*, const double );
cBST_BOOL cBST_SearchString( cBST*, const char* );

/**
 * Delete Int/Double/String value from cBST.
 */
cBST_BOOL cBST_DeleteInt( cBST**, const int );

#ifdef __cplusplus
}
#endif

#endif
